<template>
	<view>
		<view class='top-wrap'>
		  <view class='ok-msg'>支付成功 明早记得打卡哦</view>
		  <view class='msg'>打卡时间<text class='time'>明日5:00-8:00</text></view>
		</view>
		<button class='red-btn' @click='back()'>返回</button>
		<button class='org-btn' open-type="share" >邀请好友参与挑战</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				share: {
					title: '早起打卡，养成好习惯，打卡瓜分奖池，赢🧧',//自定义标题
					path: `/subpkg/earlyclock/index/index`,  //默认跳转首页
					imageUrl:'https://cos.xunmeng.icu/cartoonrabbit/static/earlyshare.png'
				}
			};
		},
		methods:{
			back(){
				uni.navigateBack({
					delta:1
				})
			}
		},
		async onShareAppMessage(res) { //发送给朋友
			let that = this
			// 动态获取当前页面栈
			let pages = getCurrentPages(); //获取所有页面栈实例列表
			let nowPage = pages[pages.length - 1]; //当前页页面实例
			// let prevPage = pages[pages.length - 2]; //上一页页面实例
			// that.share.path = `/${nowPage.route}`
			// 获取token
			let token=uni.getStorageSync('token')
			if(token){
				token=JSON.parse(token)
			}else{
				await uni.showToast({
					title: '未授权请先登录',
					icon: 'none'
				})
				return
			}
			// 获取用户的唯一标识
			const resoult=await http({
				url:'/user/useronlyId',
				method:"GET",
				header:{
					Authorization:token.data
				}
			})
			let params=''
			if(resoult.code==200){
				params='?scene='+resoult.data
			}else{
				await uni.showToast({
					title: '获取参数异常',
					icon: 'none'
				})
				return
			}
			return {
				title: this.share.title,
				path: this.share.path+params,
				imageUrl: this.share.imageUrl,
				funtion:(function() {
					uni.showToast({
						title: '分享成功'
					})
					// 判断制作次数是否可以加一
					// 获取是否可分享的时间戳与当前时间戳进行对比
					let canGetProductionTime= uni.getStorageSync('canGetProductionTime')
					// 与当前时间进行对比
					const currentTimestamp = Date.parse(new Date());
					if(!canGetProductionTime||((currentTimestamp-canGetProductionTime)/60/60/1000>24)){
						// 调用制作次数加一
						if(token.data){
							
							http({
								url:'/user/production/change/1',
								method:"POST",
								header:{
									Authorization:token.data
								}
							}).then(res=>{
								if(res.code==200){
									uni.showToast({
										title: '制作次数+1',
										icon: 'none'
									})
									uni.setStorageSync('canGetProductionTime',currentTimestamp)
									that.$store.commit('m_user/updateUserInfo',res.data)
								}
							})
						}
					}else{
						uni.setStorageSync('canGetProductionTime',currentTimestamp)
					}
					
				})()
			}
		},
		async onShareTimeline(res) { //分享到朋友圈
		let that = this
			// 动态获取当前页面栈
			let pages = getCurrentPages(); //获取所有页面栈实例列表
			let nowPage = pages[pages.length - 1]; //当前页页面实例
			// let prevPage = pages[pages.length - 2]; //上一页页面实例
			// that.share.path = `/${nowPage.route}`
			// 获取token
			let token=uni.getStorageSync('token')
			if(token){
				token=JSON.parse(token)
			}else{
				await uni.showToast({
					title: '未授权请先登录',
					icon: 'none'
				})
				return
			}
			// 获取用户的唯一标识
			const resoult=await http({
				url:'/user/useronlyId',
				method:"GET",
				header:{
					Authorization:token.data
				}
			})
			let params=''
			if(resoult.code==200){
				params='?scene='+resoult.data
			}else{
				await uni.showToast({
					title: '获取参数异常',
					icon: 'none'
				})
				return
			}
			return {
				title: this.share.title,
				path: this.share.path+params,
				imageUrl: this.share.imageUrl,
				funtion:(function() {
					uni.showToast({
						title: '分享成功'
					})
					// 判断制作次数是否可以加一
					// 获取是否可分享的时间戳与当前时间戳进行对比
					let canGetProductionTime= uni.getStorageSync('canGetProductionTime')
					// 与当前时间进行对比
					const currentTimestamp = Date.parse(new Date());
					if(!canGetProductionTime||((currentTimestamp-canGetProductionTime)/60/60/1000>24)){
						// 调用制作次数加一
						// 获取token
						let token=uni.getStorageSync('token')
						if(token){
							token=JSON.parse(token)
						}
						if(token.data){
							
							http({
								url:'/user/production/change/1',
								method:"POST",
								header:{
									Authorization:token.data
								}
							}).then(res=>{
								if(res.code==200){
									uni.showToast({
										title: '制作次数+1',
										icon: 'none'
									})
									uni.setStorageSync('canGetProductionTime',currentTimestamp)
									that.$store.commit('m_user/updateUserInfo',res.data)
								}
							})
						}
					}else{
						uni.setStorageSync('canGetProductionTime',currentTimestamp)
					}
					
				})()
			}
		},
	}
</script>
<style>
	page{
		background: #FFFFFF;
	}
</style>
<style lang="scss" scoped>
/* pages/pay-success/pay-success.wxss */
.top-wrap{
  height: 332rpx;
  background: url();
  background-size: 100% 100%;
  display: flex;
  flex-direction: column;
   align-items: center; 
}
.ok-msg{
  font-size: 50rpx;
  color: #fff;
  margin-top: 60rpx;
}
.msg{
  font-size: 28rpx;
  color: #fff;
   margin-top: 10rpx; 
}
.time{
  color: #ffee2b
}
.red-btn{
  width: 691rpx;
  background: #ff8e42;
  color: #ffffff;
  font-size: 34rpx;
  /* border: none; */
  border-radius: 0;
  margin-top: 40rpx;
  height: 112rpx;
  line-height:112rpx;
}
.red-btn::after{
  border: none
}
.org-btn{
  width: 691rpx;
  background: #ffb932;
  color: #ffffff;
  font-size: 34rpx;
  /* border: none; */
  border-radius: 0;
  margin-top: 30rpx;
  border: 1rpx solid #ffb932;
  height: 112rpx;
  line-height:112rpx;
}
.org-btn::after{
  border: none
}
</style>
